<?php 
 
class Cms_Xml extends DomDocument
{ 
    public $Dom ; 
	public $Root;
	public $Child;
	
    public function __construct( $roots = null , $stylesheet = null )
	{
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
		header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
		header("Cache-Control: no-cache, must-revalidate" );
		header("Pragma: no-cache" );
		header("Content-type: text/xml");
		$this->Dom = new DomDocument('1.0');
		$this->Root = $this->Dom->createElement($roots);
		$this->Root = $this->Dom->appendChild($this->Root);
	}
 
    public function getNode( $xpath , $index = null ) 
	{
	} 
 
    public function existsNode( $xpath , $index = null )
	{
	} 
 
    public function appendRoot( $roots )
	{
	}
	//$xml->appendChild( '//' , array('username'=>'Daniele Orlando') , array('type'=>'string') ) ; 
    public function appendChild( $xpaths , $childs , array $attributes = array() , $text = null )
	{
		if($xpaths =='//')
		{
			$ParentNode = $this->Root;
		}
		else
		{
			$nodelist = $this->Dom->getElementsByTagName($xpaths);
			foreach($nodelist as $Node)
			{
				$ParentNode = $Node;
			}	
		}
			
		foreach($childs as $node => $value)
		{
			$Child = $ParentNode->appendChild($this->Dom->createElement($node));
			if(!empty($value))
			{
				$ChildValue = $this->Dom->createTextNode($value);
    			$ChildValue = $Child->appendChild($ChildValue);
			}
			else
			{
				$Child = $ParentNode->appendChild($Child);
			}
			
			$this->Child = $Child;
			
			$this->setAttribute($Child,$attributes);
		}
		
	}
 
    public function setAttribute( $Child , $attributes )
	{
		foreach($attributes as $attribute => $value)
		{
			$this->Child->setAttribute($attribute, $value);
		}
	}
 
    public function createText( $xpaths , $texts )
	{
		return $Dom->saveXML();
	}
	
	public function saveXml()
	{
		return $this->Dom->saveXml();
	}
} 
 
?>